<template>
  <el-form :inline="true" :model="formInline" class="demo-form-inline">
    <el-form-item label="名称">
      <el-input v-model="formInline.user" placeholder="属性名称"></el-input>
    </el-form-item>
    <el-form-item label="分类">
      <el-select v-model="formInline.region" placeholder="请选择">
        <el-option
          :label="item.name"
          :value="item.id"
          v-for="item in attribute.category"
          :key="item.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">查询</el-button>
      <el-button type="primary" @click="addSubmit">添加</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
//引入api
import { getAdminAttribute } from "@/request/api.js";

//引入vuex
import { mapState } from "vuex";
export default {
  data() {
    return {
      formInline: {}
    };
  },
  // 方法
  methods: {
    onSubmit() {
      getAdminAttribute({
        name: this.formInline.user,
        c_id:this.formInline.region,
        pages: this.$store.state.attribute.pageSize,
        currentPage: this.$store.state.attribute.currentPage
      }).then(res => {
        this.$store.commit("attribute/attributeList", res.data);
      });
    },
    addSubmit() {
      this.$router.push("/addattribute");
    }
  },
  computed: {
    ...mapState(["attribute"])
  }
};
</script>

<style lang='less' scoped>
.el-form {
  background-color: #fff;
  // overflow: hidden;
  height: 42px;
}
</style>